import 'package:aitao_flutter/const/common_const.dart';
import 'package:aitao_flutter/login/controller/forget_password_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';

import '../../common_ui/back_nav.dart';
import '../../common_ui/confirm_btn.dart';
import '../../style/box_style.dart';
import '../../style/color_style.dart';
import '../../style/edgeInsets_style.dart';
import '../../style/radius_style.dart';
import '../../style/text_style.dart';

class ForgetPasswordPage extends StatelessWidget {
  const ForgetPasswordPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BackNavigation(
          titleColor: ColorStyle.whiteColor,
          title: LoginStringConst.forgetPasswordText,
          backGroundColor: ColorStyle.themeColor,
        ),
        backgroundColor: ColorStyle.themeColor,
        body: GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () {
              // 点击空白区域时收起键盘
              FocusScope.of(context).unfocus();
            },
            child: GetBuilder<ForgetPassWordController>(
              init: ForgetPassWordController(),
              builder: (controller) {
                return CustomScrollView(slivers: [
                  // 输入框
                  inputWidget(controller),
                  loginBtnWidget(controller),
                ]);
              },
            ))
    );
  }

  Widget inputWidget(ForgetPassWordController controller) {
    return SliverToBoxAdapter(
        child: Container(
            decoration: BoxDecoration(
              borderRadius: RadiusStyle.radiusAll(14),
              color: ColorStyle.whiteColor,
            ),
            margin: EdgeInsetsStyle.customMargin(20, 70, 20, 0),
            padding: EdgeInsetsStyle.customMargin(30, 50, 20, 50),
            child: Column(
              children: [
                // 手机号
                Container(
                  height: 44.h,
                  padding: EdgeInsetsStyle.edgeInsets(20, 0),
                  decoration: BoxDecoration(
                      borderRadius: RadiusStyle.radiusAll(25),
                      color: const Color(0xFFF5F7F7)),
                  child: Row(children: [
                    Expanded(
                        child: TextField(
                          controller: controller.phoneController,
                          keyboardType: TextInputType.number,
                          textInputAction: TextInputAction.next,
                          decoration: const InputDecoration(
                            hintText: LoginStringConst.inputPhoneHintText,
                            border: InputBorder.none,
                          ),
                        ))
                  ]),
                ),
                Box.vBox30,
                // 密码
                Container(
                  height: 44.h,
                  padding: EdgeInsetsStyle.edgeInsets(20, 0),
                  decoration: BoxDecoration(
                      borderRadius: RadiusStyle.radiusAll(25),
                      color: const Color(0xFFF5F7F7)),
                  child: Row(children: [
                    Expanded(
                        child: TextField(
                          controller: controller.passwordController,
                          textInputAction: TextInputAction.next,
                          decoration: const InputDecoration(
                            hintText: LoginStringConst.inputPassWordText,
                            border: InputBorder.none,
                          ),
                        ))
                  ]),
                ),
                Box.vBox30,
                // 验证码
                Container(
                  height: 44.h,
                  padding: EdgeInsetsStyle.edgeInsets(20, 0),
                  decoration: BoxDecoration(
                      borderRadius: RadiusStyle.radiusAll(25),
                      color: const Color(0xFFF5F7F7)),
                  child: Row(children: [
                    Expanded(
                        child: TextField(
                          controller: controller.codeController,
                          keyboardType: TextInputType.number,
                          textInputAction: TextInputAction.next,
                          decoration: const InputDecoration(
                            hintText: LoginStringConst.inputVerCodeText,
                            border: InputBorder.none,
                          ),
                        )),
                    GestureDetector(
                      child: Text(
                          controller.isCountingDown == true
                              ? '${controller.countdownSeconds}秒后重新获取'
                              : LoginStringConst.getVerCodeText,
                          style: controller.isCountingDown == false
                              ? Styles.blueText_12
                              : Styles.mainText_12),
                      onTap: () {
                        controller.getSmsCode();
                      },
                    )
                  ]),
                ),

              ],
            )));
  }

  Widget loginBtnWidget(ForgetPassWordController controller) {
    return SliverToBoxAdapter(
        child: Container(
            margin: EdgeInsetsStyle.customMargin(20, 60, 20, 0),
            child: ConfirmButton(
              title: LoginStringConst.confirmChangeText,
              callBack: () {
                controller.submitClick();
              },
            )));
  }
}
